<template>
  <!-- 题型管理 -->
  <div class="app-container">
    <!-- 查询 -->
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
    >
        <el-form-item label="科目:" prop="subjectId">
            <el-select v-model="queryParams.subjectId" placeholder="请选择科目" clearable size="small" >
                <el-option
                v-for="dict in kelist"
                :key="dict.id"
                :label="dict.name"
                :value="dict.id"
                />
            </el-select>
        </el-form-item>
        
         <el-form-item label="试卷名称:" prop="paperName">
            <el-input
            v-model="queryParams.paperName"
            placeholder="请输入试卷名称"
            clearable
            size="small"
            @keyup.enter.native="handleQuery"
            />
        </el-form-item>

        <el-form-item>
            <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery"
            >搜索</el-button
            >
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
            >重置</el-button
            >
        </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          v-hasPermi="['system:exampaper:add']"
          @click="handleAdd"
          >试卷生成
        </el-button>
        <el-button
          type="primary"
          plain
          icon="el-icon-download"
          size="mini"
          v-hasPermi="['system:exampaper:add']"
          :disabled="multiple"
          @click="excelAllTemplate"
          >excel汇总导出
        </el-button>
        <!-- xiaAllTemplate -->
        <el-button
          type="primary"
          plain
          icon="el-icon-download"
          size="mini"
          v-hasPermi="['system:exampaper:add']"
          :disabled="multiple"
          @click="xiaAllTemplate"
          >word汇总导出
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" ></right-toolbar>
    </el-row>
    <!-- 题型管理表 -->
    <el-table
      v-loading="loading"
      :data="infoList"
      @selection-change="handleSelectionChange"
      ref="multipleTable"
      :row-key="getRowKeys"
      @row-click="handleRowClick" 
      :row-class-name="tableRowClassName"
    >
      <el-table-column type="selection" :reserve-selection="true" width="50" align="center" />
      <!-- <el-table-column width="50">
        <template slot-scope="scope">
          <input
            type="checkbox"
            v-model="scope.row.instatus"
            @change="xuanchange(scope.row)"
          />
        </template>
      </el-table-column> -->
      
      <el-table-column
        label="序号"
        type="index"
        width="70"
        :index="indexMetthod"
        align="center"
      >
      </el-table-column>
      <el-table-column label="科目" align="center" prop="subject" />
      <el-table-column label="试卷名称" align="center" prop="paperName" />
      <el-table-column label="试卷编码" align="center" prop="paperNumber" />
      <el-table-column label="发布时间" align="center" prop="releaseTime" />
      <el-table-column label="策略" align="center" prop="assembly" />
      <el-table-column label="地市" align="center" prop="area" />
      <!-- <el-table-column label="考试日期" align="center" prop="examTime" /> -->
      <!-- <el-table-column label="难易度" align="center" prop="difficulty" >
          <template slot-scope="scope">
          <span v-if="scope.row.difficulty == 1">0</span>
          <span v-else-if="scope.row.difficulty == 2">0.1</span>
          <span v-else-if="scope.row.difficulty == 3">0.2</span>
          <span v-else-if="scope.row.difficulty == 4">0.3</span>
          <span v-else-if="scope.row.difficulty == 5">0.4</span>
          <span v-else-if="scope.row.difficulty == 6">0.5</span>
          <span v-else-if="scope.row.difficulty == 7">0.6</span>
          <span v-else-if="scope.row.difficulty == 8">0.7</span>
          <span v-else-if="scope.row.difficulty == 9">0.8</span>
          <span v-else-if="scope.row.difficulty == 10">0.9</span>
          <span v-else-if="scope.row.difficulty == 11">0.10</span>
          <span v-else>暂无状态</span>
        </template>
      </el-table-column> -->
      <el-table-column label="难易度" align="center" prop="difficulty" />
      
      <el-table-column label="试卷状态" align="center" prop="status">
        <template slot-scope="scope">
          <span v-if="scope.row.status == 0">未发布</span>
          <span v-else-if="scope.row.status == 1">已发布</span>
          <span v-else>暂无状态</span>
        </template>
      </el-table-column>

      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="200px"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:paper:edit']"
            >修改</el-button>
            <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:paper:remove']"
            >删除</el-button>
            <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="chaUpdate(scope.row)"
            v-hasPermi="['system:paper:query']"
            >查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页器 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 修改题型描述对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <!-- 考试名称    科目 -->
        <el-row>
          <el-col :span="12">
            <el-form-item label="考试名称" prop="examTypeId" v-if="chashow == false" >
                <el-select v-model="form.examTypeId" placeholder="请选择考试名称">
                    <el-option
                    v-for="item in shilist"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                    />
                </el-select>
            </el-form-item>
            <el-form-item label="考试名称" prop="examTypeId" v-else>
                <el-select v-model="form.examTypeId" placeholder="请选择考试名称" :disabled="true">
                    <el-option
                    v-for="item in shilist"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                    />
                </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="科目" prop="subjectId" v-if="chashow == false" >
                <el-select v-model="form.subjectId" placeholder="请选择" ref="gain" @change="kechange" >
                    <el-option
                    v-for="item in kelist"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                    />
                </el-select>
            </el-form-item>
            <el-form-item label="科目" prop="subjectId" v-else >
                <el-select v-model="form.subjectId" placeholder="请选择" :disabled="true" >
                    <el-option
                    v-for="item in kelist"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                    />
                </el-select>
            </el-form-item>
          </el-col>
          
        </el-row>
        <!-- 总题数 策略 -->
        <el-row>
          <el-col :span="12">
            <el-form-item label="策略" prop="assemblyId" v-if="chashow == false" >
                <el-select v-model="form.assemblyId" placeholder="请选择" @change="celue(form.assemblyId)">
                    <el-option
                    v-for="item in celist"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                    />
                </el-select>
            </el-form-item>
            <el-form-item label="策略" prop="assemblyId" v-else >
                <el-select v-model="form.assemblyId" placeholder="请选择" :disabled="true">
                    <el-option
                    v-for="item in celist"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                    />
                </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
              <el-form-item label="试卷难易度" prop="difficultyDegree">
                <el-input
                  :disabled="true"
                  v-model.trim="form.difficultyDegree"
                  maxlength="90"
                  style="width:218px;"
                />
              </el-form-item>
          </el-col>
        </el-row>
        
        <!-- 试卷名称 试卷编码 -->
        <el-row>
          <el-col :span="12">
            <el-form-item label="试卷名称" prop="paperName" v-if="chashow == false">
              <el-input
                v-model.trim="form.paperName"
                placeholder="请输入试卷名称"
                maxlength="90"
                style="width:218px;"
              />
            </el-form-item>
            <el-form-item label="试卷名称" prop="paperName" v-else >
              <el-input
                :disabled="true" 
                v-model.trim="form.paperName"
                maxlength="90"
                style="width:218px;"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="试卷编码" prop="paperNumber" v-if="chashow==false">
                <el-input
                  v-model.trim="form.paperNumber"
                  placeholder="请输入试卷编码"
                  maxlength="90"
                  style="width:218px;"
                />
            </el-form-item>
            <el-form-item label="试卷编码" prop="paperNumber" v-else>
              <el-input
                :disabled="true"
                v-model.trim="form.paperNumber"
                maxlength="90"
                style="width:218px;"
              />
            </el-form-item>
          </el-col>
        </el-row>
        
        <!--总题数    总分数  -->
        <el-row>
          <el-col :span="12">
            <el-form-item label="总题数" prop="total">
              <el-input
                :disabled="true"
                v-model.trim="form.total"
                maxlength="90"
                style="width:218px;"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="总分数" prop="totalScore">
              <el-input
                :disabled="true"
                v-model.trim="form.totalScore"
                maxlength="90"
                style="width:218px;"
              />
            </el-form-item>
          </el-col>
          
          
        </el-row>
        
        <!-- 地市  状态-->
        <el-row>
          <el-col :span="8">
            <el-form-item label="所属地市" prop="shi" >
            <el-select v-model="form.shi" placeholder="请选择省份" style="width:150px;" @change="changearea" :disabled="true" >
                <el-option 
                v-for="item in arealist"
                :key="item.id"
                :label="item.name"
                :value="item.id"
                />
            </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="3">
            <el-select v-model="form.belongArea" placeholder="请选择市区" style="width:120px;" :disabled="true" >
                <el-option 
                v-for="item in qulist"
                :key="item.id"
                :label="item.name"
                :value="item.id"
                />
            </el-select>
          </el-col>
          <el-col :span="12">
            <el-form-item label="状态" v-if="chashow == false">
              <el-radio-group v-model="form.status">
                <el-radio :label="1">已发布</el-radio>
                <el-radio :label="0">未发布</el-radio>
              </el-radio-group>
            </el-form-item>
            <el-form-item label="状态" v-else>
              <div>
                <span v-if="form.status == 1">已发布</span>
                <span v-if="form.status == 0">未发布</span>
              </div>
            </el-form-item>
          </el-col>
        </el-row>
        <!-- 修改时的试题信息 -->
        <el-form-item v-if="form.rtExamPaperQuestions" >
          <div style="margin-left:-100px;">
            <div class="tabletop">
              <span>试题ID</span>
              <span>试题分值</span>
              <!-- <div>操作</div> -->
              <span></span>
            </div>
            <ul>
              <li v-for="(item,index) in form.rtExamPaperQuestions" :key="index">
                <div class="tabletop">
                  <span>
                    {{form.rtExamPaperQuestions[index].questionId}}
                  </span>
                  <span>
                    {{form.rtExamPaperQuestions[index].score}}
                  </span>
                  <span class="chabottom" @click="chaclick(form.rtExamPaperQuestions[index].questionId)">
                    查看
                  </span>
                </div>
              </li>
            </ul>
          </div>
        </el-form-item>
        <!-- 试卷编码 -->
        <!-- **************************************************** -->
        <!-- 考试题比例 练习题比例 -->
        <el-row>
          <el-col :span="12">
            <el-form-item label="考试题比例" prop="bilia" v-if="chashow == false">
              <el-input
                v-model="form.bilia"
                placeholder="请输入考试题比例"
                maxlength="90"
                style="width:218px;"
              />
            </el-form-item>
            <el-form-item label="考试题比例" prop="bilia" v-else >
              <el-input
                :disabled="true" 
                v-model="form.bilia"
                maxlength="90"
                style="width:218px;"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="考试题比例" prop="bilib" v-if="chashow==false">
                <el-input
                  v-model="form.bilib"
                  placeholder="请输入考试题比例"
                  maxlength="90"
                  style="width:218px;"
                />
            </el-form-item>
            <el-form-item label="考试题比例" prop="bilib" v-else>
              <el-input
                :disabled="true"
                v-model="form.bilib"
                maxlength="90"
                style="width:218px;"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <!-- **************************************************** -->

        <!-- 备注 -->
        <el-form-item label="备注" prop="remark" v-if="chashow==false">
          <el-input
            v-model="form.remark"
            type="textarea"
            placeholder="请输入内容"
            maxlength="200"
          ></el-input>
        </el-form-item>
        <el-form-item label="备注" prop="remark" v-else>
          <el-input
            :disabled="true"
            v-model="form.remark"
            type="textarea"
            placeholder="请输入内容"
            maxlength="200"
          ></el-input>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" v-if="!chashow" @click="submitForm">确 定</el-button>
        <el-button type="primary" v-hasPermi="['system:paper:export']" v-if="chashow" @click="xiaTemplate">导出试卷</el-button>
        
        <el-button type="primary" v-hasPermi="['system:paper:export']" v-if="chashow" @click="excelTemplate">导出excel</el-button>

        <el-button type="primary" v-hasPermi="['system:paper:export']" v-if="chashow" @click="daTemplate">导出答案</el-button>

        <el-button type="primary" v-if="chashow" @click="duplicate">试卷查重</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 查看 -->
    <el-dialog
    :title="audittitle"
    :visible.sync="auditopen"
    width="1200px"
    append-to-body
    >
      <el-form label-width="120px" :model="auditform" >
        <!-- 第一行   科目 章 节 知识点 -->
        <el-row>
          <el-col :span="6">
            <el-form-item label="科目" prop="subjectId" >
            <el-select v-model="auditform.subjectId" placeholder="无" ref="gain" :disabled="true">
                <el-option
                v-for="item in kelist"
                :key="item.id"
                :label="item.name"
                :value="item.id"
                />
            </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="章" prop="zhang" >
            <el-select v-model="auditform.zhang" placeholder="无"   :disabled="true">
                <el-option
                v-for="item in zlist"
                :key="item.id"
                :label="item.name"
                :value="item.id"
                />
            </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="节" prop="jie" >
            <el-select v-model="auditform.jie" placeholder="无" :disabled="true">
                <el-option
                v-for="item in jlist"
                :key="item.id"
                :label="item.name"
                :value="item.id"
                />
            </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="知识点" prop="knowledgeId" >
            <el-select v-model="auditform.knowledgeId" placeholder="无"  :disabled="true" >
                <el-option 
                v-for="item in outlineList"
                :key="item.id"
                :label="item.name"
                :value="item.id"
                />
            </el-select>
            </el-form-item>
          </el-col>

        </el-row>
        <!-- 第二行   错误率  知识点重要度   地市 -->
        <el-row>
          <el-col :span="6">
            <el-form-item label="错误率" prop="difficulty" >
            <el-select v-model="auditform.difficulty" placeholder="无" :disabled="true" >
                <el-option 
                v-for="item in difficultylist"
                :key="item.id"
                :label="item.difficultyName"
                :value="item.id"
                />
            </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="知识点重要度" prop="importanceId" >
            <el-select v-model="auditform.importanceId" :disabled="true" >
                <el-option 
                v-for="item in outlineList"
                :key="item.id"
                :label="item.importance"
                :value="item.importanceId"
                />
            </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="7">
            <el-form-item label="所属地市" prop="shi" >
            <el-select v-model="auditform.shi" placeholder="无" style="width:190px;"  :disabled="true" >
                <el-option 
                v-for="item in arealist"
                :key="item.id"
                :label="item.name"
                :value="item.id"
                />
            </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="5">
            <el-select v-model="auditform.belongArea" placeholder="无" style="width:160px;" :disabled="true" >
                <el-option 
                v-for="item in qulist"
                :key="item.id"
                :label="item.name"
                :value="item.id"
                />
            </el-select>
          </el-col>

          

        </el-row>
        <!-- 第三行   题型    命题人   试题时效 -->
        <el-row>
          <el-col :span="5">
            <el-form-item label="题型" prop="questionTypeId" >
            <el-select v-model="auditform.questionTypeId" placeholder="请选择"   :disabled="true">
                <el-option 
                v-for="item in typelist"
                :key="item.id"
                :label="item.name"
                :value="item.id"
                />
            </el-select>
            </el-form-item>
          </el-col>
          
          <el-col :span="5">
            <el-form-item label="命题人" prop="expertName">
            <el-select v-model="auditform.expertName" placeholder="请选择"   :disabled="true">
                <el-option 
                v-for="item in personlist"
                :key="item.userId"
                :label="item.userName"
                :value="item.userId"
                />
            </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="5">
            <el-form-item label="试题时效" prop="aging" >
            <el-select v-model="auditform.aging" placeholder="无" :disabled="true" >
                <el-option 
                v-for="item in aginglist"
                :key="item.id"
                :label="item.name"
                :value="item.id"
                />
            </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="5" v-if="auditform.aging == 0">
            <el-form-item label="有效期限" prop="validTime">
                <el-date-picker clearable size="small"
                    v-if="auditform.aging !==1"
                    v-model="auditform.validTime"
                    type="date"
                    value-format="yyyy-MM-dd"
                    placeholder="无">
                </el-date-picker>
                
                <el-input v-else  v-model.trim="form.code" placeholder="请输入" maxlength="10" style="width:218px;" :disabled="true"  />
            </el-form-item>
          </el-col>

        </el-row>
        <el-row>
          <!-- 题干  材料背景 -->
          <el-col >
            <el-form-item label="材料背景:" v-if="auditform.questionTypeId == 5">
              <div class="imgwidth" v-if="auditform.subject" v-html="auditform.questionsContent" ></div>
            </el-form-item>

            <el-form-item label="题干:" v-else>
              <div class="imgwidth" v-if="auditform.subject" v-html="auditform.questionsContent" ></div>
            </el-form-item>
            <!-- <img src="/dev-api/profile/upload/2023/03/30/f3f68a9d-0812-4234-a41c-866be420f584.jpg"> -->
            <!-- <img src="/prod-api/profile/upload/2022/07/19/fa9fd903-3737-4c09-8784-d7cfac667449.png"> -->
          </el-col>
          <!-- 单选多选题 -->
          <el-col v-if="auditform.questionTypeId == 1 || auditform.questionTypeId == 2" >
            <el-form-item label="选项信息:" >
              <ul v-for="(item,index) in auditform.rtOptionsInfos" :key="index" style="display: flex; font-size: 20px;">
                <li>
                  <input type="checkbox" v-model="item.instatus" onclick="return false;" checked="checked">
                  <span v-html="item.option"></span>
                </li>
                <li class="imgwidth" v-html="item.remark" style="margin-left:20px;" ></li>
              </ul>
            </el-form-item>
            <el-form-item label="试题答案:">
              <dir  style="display: flex; font-size: 20px;">
                <div v-for="(item,index) in auditform.rtOptionsInfos" :key="index">
                  <span v-if="item.instatus == 1" v-html="item.option"></span>
                </div>
              </dir>
            </el-form-item>
          </el-col>
          <!-- 判断题 -->
          <el-col v-if="auditform.questionTypeId == 4" >
            <el-form-item label="选项信息:" >
              <ul v-for="(item,index) in auditform.rtOptionsInfos" :key="index" style="display: flex; font-size: 20px;">
                <li>
                  <input type="checkbox" v-model="item.instatus" onclick="return false;" checked="checked">
                  <span v-html="item.option"></span>
                </li>
                <li v-html="item.text" style="margin-left:20px;" ></li>
              </ul>
            </el-form-item>
            <el-form-item label="试题答案:">
              <dir v-for="(item,index) in auditform.rtOptionsInfos" :key="index">
                <span v-if="item.instatus == 1" v-html="item.text"></span>
              </dir>
            </el-form-item>
          </el-col>
          <!-- 案例题 -->
          <el-col v-if="auditform.questionTypeId == 5" >
            <div v-for="(item,index) in auditform.rtQuestionsInfos" :key="index">
              <!-- 案例题小题题干序号 -->
              <div style="text-align: center; margin-top:20px;">小题({{index+1}})</div>
              <el-form-item label="试题题干:" >
                  <div class="imgwidth" v-html="auditform.rtQuestionsInfos[index].questionsContent"></div>
              </el-form-item>
              <!-- 案例单选题 -->
              <div v-if="auditform.rtQuestionsInfos[index].questionTypeId == 1" >
                <el-form-item label="选项信息:">
                  <ul v-for="(list,key) in auditform.rtQuestionsInfos[index].rtOptionsInfos" :key="key" style="display: flex; font-size: 20px;">
                    <li>
                      <input type="checkbox" v-model="list.instatus" onclick="return false;" checked="checked">
                      <span v-html="list.option"></span>
                    </li>
                    <li class="imgwidth" v-html="list.remark" style="margin-left:20px;" ></li>
                  </ul>
                </el-form-item>
                <el-form-item label="试题答案:">
                  <dir v-for="(loop,index) in auditform.rtQuestionsInfos[index].rtOptionsInfos" :key="index">
                    <span v-if="loop.instatus == 1" v-html="loop.option"></span>
                  </dir>
                </el-form-item>
              </div>
              <!-- 案例问答题 -->
              <el-form-item v-if="auditform.rtQuestionsInfos[index].questionTypeId == 6" label="问答答案:">
                <div class="imgwidth" v-html="auditform.rtQuestionsInfos[index].answer">

                </div>
              </el-form-item>
            </div>

          </el-col>
          <!-- 问答题 -->
           <el-col v-if="auditform.questionTypeId == 6" >
            <el-form-item label="问答答案:">
              <dir>
                <span class="imgwidth" v-html="auditform.answer"></span>
              </dir>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="auditcancel">关 闭</el-button>
      </div>
    </el-dialog>
            <!-- 查重试题对话框 -->
    <el-dialog
    :title="chatitle"
    :visible.sync="chatopen"
    width="800px"
    append-to-body
    >
      <el-table 
      v-loading="loading" 
      :data="chainfo" 
      :row-class-name="tableRowClassName"
      >
        <el-table-column label="试题编号" align="center" prop="id" width="80" />
        <el-table-column label="题型" align="center" prop="questionType" width="80" />
        <el-table-column label="题干" align="center" prop="questionsContent" />
        <el-table-column label="科目" align="center" prop="subject" width="80" />
        <el-table-column label="知识点" align="center" prop="knowledge" width="150" />
              <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="100">
        <template slot-scope="scope">
            <span class="chainfoclick" @click="chainfoclick(scope.row)">查看</span>
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click="chacel">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listInfo,
  getInfo,
  addInfo,
  updateInfo,
  listType,
  infoList,
  areainfo,
  areasinfo,
  shiList,
  delInfo,
  shitigetInfo,
  outlineinfo,
  difficultyinfo,
  personinfo,
  typeinfo,
  importTemplate,
  daanlate,
  duplicategetInfo,
  excelimportTemplate,
  excelimportTemplates,
  importTemplates,
} from "@/api/system/maintain";

export default {
  name: "outline",
  data() {
    return {
       // 弹出层标题 查重
      chatitle: "",
      // 是否显示弹出层 查重
      chatopen: false,
      // 查重列表
      chainfo:[],
      chainfoid:{
        pageNum: 1,
        pageSize: 10,
        questionId:null,
      },
      // 查看显示取消
      chashow:false,
      // 章下拉
      zlist:[],
      // 节下拉
      jlist:[],
      //知识点下拉
      outlineList:[],
      //难易度下拉
      difficultylist:[],
      //题型下拉
      typelist:[],
      // 命题人下拉鞋标
      personlist:[],
      //有效时效
      aginglist:[
          {
              id:1,
              name:"无"
          },
          {
              id:0,
              name:"有"
          }
      ],
      //选项A到
      test_Atrr:["【A】","【B】","【C】","【D】","【E】","【F】","【G】","【H】","【I】","【J】","【k】","【l】","【m】","【n】",
      ],
      // 弹出层标题 查看
      audittitle: "",
      // 是否显示弹出层 查看
      auditopen: false,
      // 查看列表
      auditform:{},
      // 科目下拉列表
      kelist: [],
      // 策略名称
      celist:[],
      // 地市
      arealist:[],
      //区市下拉
      qulist:[],
      //下拉列表
      examType: [],
      shilist:[],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      idsum:[],
      // 选中数组
      shiid: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 科目信息表格数据
      infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        subjectId: null,
        paperName:null,
      },
      iduqers:{
        id:null
      },
      examlist:{
        examPaperId : null,
        ids:[],
      },
      // 修改反显传值
      xiuformlist:{
        subjectId:null,
        parentId:null
      },
      quer: {
        // pageNum: 1,
        // pageSize: 10,
        subjectId: null,
      },
      // 地市
      fordishi:{
          pid:0,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        examTypeId: [
          { required: true, message: "考试名称不能为空", trigger: "change" },
        ],
        subjectId: [
          { required: true, message: "科目不能为空", trigger: "change" },
        ],
        assemblyId: [
          { required: true, message: "策略不能为空", trigger: "blur" },
        ],
        paperName: [
          { required: true, message: "试卷名称不能为空", trigger: "blur" },
        ],
        paperNumber: [
          { required: true, message: "试卷编码不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {
    this.getList();
    this.xlList();
    this.areaget()
  },
  methods: {
    // 隔行效果
    tableRowClassName({ row, rowIndex }) {
      if ((rowIndex + 1) % 2 === 0) {
        return "warning-row";
      } else {
        return "success-row";
      }
    },
    // 序号
    indexMetthod: function (index) {
      return (
        (this.queryParams.pageNum - 1) * this.queryParams.pageSize + index + 1
      );
    },
    /** 查询科目信息列表 */
    getList() {
      this.loading = true;
      listInfo(this.queryParams).then((response) => {
        this.infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    typeshi(){
      shiList().then(response =>{
        this.shilist = response.rows
        console.log(this.shilist,'shilist')
      })
    },
    // 地市下拉列表
    areaget() {
      this.loading = true;
      let pid = 0
      areainfo(this.fordishi,pid).then(response => {
        this.arealist = response.rows;
        this.loading = false;
      });
    },
    changearea(value){
        console.log('value')
        let list = {...this.form}
        list.belongArea = list.shi
        let type = list.belongArea
        // 区市列表查询
        areainfo(list,type).then(response => {
            this.form.belongArea = null //选择省时清空市区list并且改变市区list 
            this.qulist = response.rows;
            this.loading = false;
        });
    },
      //区change事件
    celue(assemblyId){
      this.form.belongArea = null
      for(var i=0;i<this.celist.length;i++){
        if(this.celist[i].id == assemblyId){
          this.form.totalScore = this.celist[i].totalScore
          this.form.total = this.celist[i].totalQuestions
          this.form.difficultyDegree = this.celist[i].difficultyDegree
        }
      }
      console.log(this.form.totalScore,'totalScore')
      console.log(this.form.total,'total')
      // this.form.totalScore = this.form.assemblyId
      // this.form.total = this.form.assemblyId
      for(var i=0;i<this.celist.length;i++){
        if(this.form.assemblyId == this.celist[i].id){
          this.form.belongArea = this.celist[i].belongArea
        }
      }
      // 地市反显
        if(this.form.belongArea != null){
          console.log('测试.........')
          areainfo(this.fordishi,0).then(response => {
            this.arealist = response.rows;
            this.loading = false;
          });
           // 存市的id
          let id = this.form.belongArea
          // 存省的id
          let pid = null
          //请求全部的省和市
          areasinfo().then(response => {
            let list = []
            list = response.rows;
            // 遍历id跟返回值一样的id
            for(let i=0;i<list.length;i++){
              if(list[i].id == id){
                pid = list[i].pid
                this.form.shi = pid
              }
            }
          }).then(()=>{
            areainfo(this.form,pid).then(response => {
              this.qulist = response.rows;
            });
          });
        }else{
          areainfo(this.fordishi,0).then(response => {
            this.arealist = response.rows;
            this.loading = false;
          });
        }
    },
    // 科目下拉
    xlList() {
      this.loading = true;
      listType().then(response => {
        this.kelist = response.rows;
        this.loading = false;
      });
    },
    kechange(){
      this.form.shi = null
      this.form.belongArea = null
      this.celist=[]
      this.form.assemblyId = null
      this.quer.subjectId=this.form.subjectId
      infoList(this.quer,this.form.subjectId).then(response => {
        this.celist = response.rows;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
      this.chashow = false
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        examTypeId: null,
        jobId: null,
        name: null,
        price: null,
        classPeriod: null,
        speaker: null,
        classPeriodConfType: null,
        invoiceName: null,
        classPeriodSign: null,
        createBy: null,
        createTime: null,
        order: null,
        shi:null,
        belongArea:null,
        status:0,
        difficultyDegree:null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.examTypeId = null;
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // xuanchange(index){
    //   console.log(index,'index')
    // },
    getRowKeys(row) {
        return row.id;
    },
    handleRowClick(row, column, event) {
      this.$refs.multipleTable.toggleRowSelection(row);
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      // this.idsum = selection.map((item) => item.id);
      // for(let i=0;i<this.idsum.length;i++){
      //   this.ids.push(this.idsum[i])
      // }
      // for(let i=0;i<this.ids.length;i++){
      //   for(let j=i+1;j<this.ids.length;j++){
      //     if(this.ids[i]==this.ids[j]){
      //       this.ids.splice(j,1);
      //       j--;
      //     }
      //   }
      // }
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
      console.log(this.ids,'ids')
    },
    // 新增
    handleAdd() {
      this.qulist = []
      this.celist = []
      this.typeshi()
      this.reset();
      this.open = true;
      this.form.bilia = '67%'
      this.form.bilib = '33%'
      this.title = "试卷生成";
      this.$nextTick(() => {
        this.$refs.gain.focus();
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      console.log(row,'xiu')
      this.chashow = false
      this.reset();
      const id = row.id || this.ids;
      getInfo(id).then((response) => {
        this.quer.subjectId = response.data.subjectId
        infoList(this.quer,this.quer.subjectId).then(response => {
          this.celist = response.rows;
        });
        this.typeshi()
        
        this.form = response.data;
        if(this.form.belongArea != null){
          console.log('测试.........')
          areainfo(this.fordishi,0).then(response => {
            this.arealist = response.rows;
            this.loading = false;
          });
           // 存市的id
          let id = this.form.belongArea
          // 存省的id
          let pid = null
          //请求全部的省和市
          areasinfo().then(response => {
            let list = []
            list = response.rows;
            // 遍历id跟返回值一样的id
            for(let i=0;i<list.length;i++){
              if(list[i].id == id){
                pid = list[i].pid
                this.form.shi = pid
              }
            }
          }).then(()=>{
            areainfo(this.form,pid).then(response => {
              this.qulist = response.rows;
            });
          });
        }else{
          areainfo(this.fordishi,0).then(response => {
            this.arealist = response.rows;
            this.loading = false;
          });
        }
        console.log(this.form,'formformform')
        this.form.bilia = '67%'
        this.form.bilib = '33%'
        // this.form.assemblyId = this.form.assemblyId+''
        this.open = true;
        this.title = "修改试卷";
      });
    },
    chaUpdate(row){
      this.chashow = true
      this.reset();
      const id = row.id || this.ids;
      this.shiid = id //存储id
      this.iduqers.id = id
      getInfo(id).then((response) => {
        this.quer.subjectId = response.data.subjectId
        console.log(this.quer,'quer')
        infoList(this.quer,this.quer.subjectId).then(response => {
          this.celist = response.rows;
        });
        this.typeshi()
        
        this.form = response.data;
        if(this.form.belongArea != null){
          areainfo(this.fordishi,0).then(response => {
            this.arealist = response.rows;
            this.loading = false;
          });
           // 存市的id
          let id = this.form.belongArea
          // 存省的id
          let pid = null
          //请求全部的省和市
          areasinfo().then(response => {
            let list = []
            list = response.rows;
            // 遍历id跟返回值一样的id
            for(let i=0;i<list.length;i++){
              if(list[i].id == id){
                pid = list[i].pid
                this.form.shi = pid
              }
            }
          }).then(()=>{
            areainfo(this.form,pid).then(response => {
              this.qulist = response.rows;
            });
          });
        }else{
          areainfo(this.fordishi,0).then(response => {
            this.arealist = response.rows;
            this.loading = false;
          });
        }
        console.log(this.form,'formformform')
        // this.form.assemblyId = this.form.assemblyId+''
        this.open = true;
        this.title = "查看试卷";
      });
    },
    // 错误率
    difficultyget() {
      this.loading = true;
      difficultyinfo().then(response => {
        this.difficultylist = response.rows;
        this.loading = false;
      });
    },
    // 命题人下拉
    personget(){
      this.loading = true;
      personinfo().then(response => {
        this.personlist = response.data;
        this.loading = false;
      });
    },
    // 题型
    typeget() {
      this.loading = true;
      typeinfo().then(response => {
        this.typelist = response.rows;
        this.loading = false;
      });
    },

    // 修改里面的查看试题详情
    chaclick(indexid){
      const id = indexid || this.ids
      shitigetInfo(id).then(response => {
        // 获取修改返回值
        this.auditform = response.data;
        // 获取科目id查询知识点下拉列表
        this.xiuformlist.subjectId = this.auditform.subjectId
        // 赋值科目id传给后台
        let type = this.xiuformlist.subjectId
        // 根据科目id查询知识点列表
        outlineinfo(this.xiuformlist,type).then(response => {
          this.outlineList = response.rows;
           // 根据知识点查询节
          for(let i=0;i<this.outlineList.length;i++){
            if(this.outlineList[i].id == this.auditform.knowledgeId){
              
              let jid = this.outlineList[i].parentId
              for(let j=0;j<this.outlineList.length;j++){
                if(this.outlineList[j].id == jid){
                  let zhangid = this.outlineList[j].parentId

                  let xlisters = {...this.xlisters}
                  xlisters.subjectId = this.auditform.subjectId
                  xlisters.parentId = this.outlineList[j].parentId
                  let type = this.outlineList[j].parentId
                  outlineinfo(this.xlisters,type).then(response => {
                    this.jlist = response.rows;
                  });
                  this.auditform.jie =  Number(jid)
                  xlisters.parentId = this.outlineList[j].parentId
                  let typeid = this.auditform.subjectId
                  outlineinfo(this.xlisters,typeid).then(response => {
                    this.zlist = response.rows;
                  });
                  this.auditform.zhang =  Number(zhangid)
                }
              }
            }
          }
        });
       
        // 反显需要转Number
        this.auditform.knowledgeId = Number(this.auditform.knowledgeId)

        // 请求错误率列表反显  错误率没有联动直接请求
        this.difficultyget()

        // 请求命题人列表反显  命题人没有联动直接请求
        this.personget()

        // 请求题型列表反显
        this.typeget()

        this.auditform.expertName = Number(this.auditform.expertName)
        // 判断有没有选择地市
        if(this.auditform.belongArea !=null){
          // 反显地市 获取地市省级下拉
          areainfo(this.fordishi,0).then(response => {
            this.arealist = response.rows;
            this.loading = false;
          });
          // 存市的id
          let id = this.auditform.belongArea
          // 存省的id
          let pid = null
          //请求全部的省和市
          areasinfo().then(response => {
            let list = []
            list = response.rows;
            // 遍历id跟返回值一样的id
            for(let i=0;i<list.length;i++){
              if(list[i].id == id){
                pid = list[i].pid
                this.auditform.shi = pid
              }
            }
          }).then(()=>{
            areainfo(this.auditform,pid).then(response => {
              this.qulist = response.rows;
            });
          });
        }else{
          areainfo(this.fordishi,0).then(response => {
            this.arealist = response.rows;
            this.loading = false;
          });
        }
        console.log(this.auditform,'this.auditform')
        

        // 判断题型 单选题
        if(this.auditform.questionTypeId == 1){
          let rtlist = this.auditform.rtOptionsInfos
          for(let i=0;i<this.auditform.rtOptionsInfos.length;i++){
            if(rtlist[i].isAnswer == 1){
              rtlist[i].instatus = true
            }else if(rtlist[i].isAnswer == 0){
              rtlist[i].instatus = false
            }else{
            }
            rtlist[i].option = this.test_Atrr[i]
          }

        }else if(this.auditform.questionTypeId == 2){  //多选题
          let rtlist = this.auditform.rtOptionsInfos
          for(let i=0;i<this.auditform.rtOptionsInfos.length;i++){
            if(rtlist[i].isAnswer == 1){
              rtlist[i].instatus = true
            }else if(rtlist[i].isAnswer == 0){
              rtlist[i].instatus = false
            }else{
            }
            rtlist[i].option = this.test_Atrr[i]
          }
        }else if(this.auditform.questionTypeId == 4){  //判断题
          if(this.auditform.isCorrect == 0){
            let list =[
              {
                instatus:false,
                isAnswer:0,
                text:"正确",
              },
              {
                instatus:true,
                isAnswer:1,
                text:"错误",
              }
            ]
            this.auditform.rtOptionsInfos = list
          }else if(this.auditform.isCorrect == 1){
            let list =[
              {
                instatus:true,
                isAnswer:1,
                text:"正确",
              },
              {
                instatus:false,
                isAnswer:0,
                text:"错误",
              }
            ]
            this.auditform.rtOptionsInfos = list
          }else{
            let list =[
              {
                instatus:false,
                isAnswer:0,
                text:"正确",
              },
              {
                instatus:false,
                isAnswer:0,
                text:"错误",
              }
            ]
            this.auditform.rtOptionsInfos = list
          }
          
        }else if(this.auditform.questionTypeId == 5){  //案例题
            let rtQinfo = this.auditform.rtQuestionsInfos
            for(let i=0;i<rtQinfo.length;i++){
              // 判断为单选题的时候进行遍历赋值ABCD等选项
              rtQinfo[i].close="×"
              if(rtQinfo[i].questionTypeId == 1){
                for(let j=0;j<rtQinfo[i].rtOptionsInfos.length;j++){
                  rtQinfo[i].rtOptionsInfos[j].option = this.test_Atrr[j]
                  if(rtQinfo[i].rtOptionsInfos[j].isAnswer == 1){
                    rtQinfo[i].rtOptionsInfos[j].instatus = true
                  }else if(rtQinfo[i].rtOptionsInfos[j].isAnswer == 0){
                    rtQinfo[i].rtOptionsInfos[j].instatus = false
                  }else{
                  }
                }
              } 
            }
        }
        
      });
      this.auditopen = true
      this.audittitle = "试题查看"
    },
    auditcancel(){
      this.auditopen = false
    },
    handleDelete(row) {
      console.log(row.id,'删除')
      const ids = row.id || this.ids;
      this.$confirm("是否确认删除当前数据?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return delInfo(ids);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    // excel导出
    excelTemplate(){
      this.examlist.examPaperId = this.iduqers.id
      excelimportTemplates(this.examlist.examPaperId).then((response)=>{
        this.download(response.msg);
      })
    },
    excelAllTemplate(){
      this.examlist.ids = this.ids
      excelimportTemplates(this.examlist.ids).then((response)=>{
        this.download(response.msg);
      })
    },
    // 批量word试卷导出
    xiaAllTemplate(){
      importTemplates(this.ids).then(response => {
        const content = response //后台返回二进制数据
        const blob = new Blob([content])
        const fileName = 'word试卷.doc'
        if ('download' in document.createElement('a')) { // 非IE下载
          const elink = document.createElement('a') //创建a标签
          elink.download = fileName //设置表名
          elink.style.display = 'none'
          elink.href = URL.createObjectURL(blob) 
          document.body.appendChild(elink)
          elink.click()
          URL.revokeObjectURL(elink.href) // 释放URL 对象
          document.body.removeChild(elink)
        } else { // IE10+下载
          navigator.msSaveBlob(blob, fileName)
        }
      });
    },
    // word试卷导出
    xiaTemplate(){
      importTemplate(this.iduqers,this.iduqers.id).then(response => {
        const content = response //后台返回二进制数据
        const blob = new Blob([content])
        const fileName = '试卷.doc'
        if ('download' in document.createElement('a')) { // 非IE下载
          const elink = document.createElement('a') //创建a标签
          elink.download = fileName //设置表名
          elink.style.display = 'none'
          elink.href = URL.createObjectURL(blob) 
          document.body.appendChild(elink)
          elink.click()
          URL.revokeObjectURL(elink.href) // 释放URL 对象
          document.body.removeChild(elink)
        } else { // IE10+下载
          navigator.msSaveBlob(blob, fileName)
        }
      });
    },
    // 导出答案
    daTemplate(){
      daanlate(this.iduqers,this.iduqers.id).then(response => {
        const content = response //后台返回二进制数据
        const blob = new Blob([content])
        const fileName = '试卷答案.doc'
        if ('download' in document.createElement('a')) { // 非IE下载
          const elink = document.createElement('a') //创建a标签
          elink.download = fileName //设置表名
          elink.style.display = 'none'
          elink.href = URL.createObjectURL(blob) 
          document.body.appendChild(elink)
          elink.click()
          URL.revokeObjectURL(elink.href) // 释放URL 对象
          document.body.removeChild(elink)
        } else { // IE10+下载
          navigator.msSaveBlob(blob, fileName)
        }
      });
    },
    // 试卷查重
    duplicate(){
      duplicategetInfo(this.shiid).then(response =>{
        if(response.rows.length >0){
          // this.$confirm('试卷试题重复', "提示", {
          //       confirmButtonText: "查看",
          //       cancelButtonText: "取消",
          //       type: "warning"
          //     }).then(()=> {
          //         this.chatopen = true;
          //         this.chainfo = response.rows
          //     }).catch(() => {});
              this.chatopen = true;
              this.chainfo = response.rows
        }else{
          this.msgSuccess("试题无重复");
        }
      })
      console.log(this.chainfo,'shiid')
    },
    // 关闭按钮   查重
    chacel(){
      this.chatopen = false;
    },
    // 查重   查看按钮
    chainfoclick(row){
      console.log(row,'row')
      console.log(row.id,'row')
      this.chashow = false
      console.log(this.indexid,'this.indexid')
      this.chaclick(row.id)
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            this.$confirm("是否确认修改数据？", "提示", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning",
            })
              .then(() => {
                updateInfo(this.form).then((response) => {
                  this.msgSuccess("修改成功");
                  this.open = false;
                  this.getList();
                });
              })
              .catch(() => {});
          } else {
            this.$confirm("是否确认新增数据？", "提示", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning",
            })
              .then(() => {
                addInfo(this.form).then((response) => {
                  this.msgSuccess("新增成功");
                  this.open = false;
                  this.getList();
                });
              })
              .catch(() => {});
          }
        }
      });
    },
  },
};
</script>
<style scoped>
/* 查重里的查看按钮 */
.chainfoclick{
  color: #1890ff;
  cursor: pointer;
}
.tabletop{
  display: flex;
  justify-content: space-evenly
}
.tabletop>span{
  display: block;
  width: 120px;
  text-align: center;
}
.tabletop>div{
  width: 120px;
  display: flex;
  justify-content: space-evenly
}
.tabletop>div>span{
  display: block;
  width: 45px;
  height: 25px;
  border-radius: 3px;
  background: rgb(161, 204, 240);
  margin: 0 auto;
  text-align: center;
  line-height: 25px;
  cursor: pointer;
}
.chabottom{
  color: rgb(161, 204, 240);
  cursor: pointer;
}
</style>
<style lang="scss" scoped>
.imgwidth{
  ::v-deep {
    img {
      width: 100%;
    }
  }
}
</style>